/*
    DESCRIPTION HERE
 */

#include "../../libraries/ae/led_effects.h"

int redPin = 12;    // LED connected to digital pin 13
int greenPin = 10;
int bluePin = 8;

int knobPin = 0; // analog in pin for potentiometer
int buttonPin = 2; // digital in pin for switch
int buttonState = 0;

int at = 1; // start at on
int delayTime = 0; // used for potentiometer data
int trigger = 0; // function to run
int lastTrigger = 0;
int displayed = 0;


// Set to 1 to enable serial debugging, be sure to set baud, too
int debug = 1;
int debug_baud = 9600;


// The setup() method runs once, when the sketch starts
void setup()   {                
  // initialize the digital pin as an output:
  pinMode(greenPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  
  randomSeed(analogRead(5));
  
  Serial.begin(debug_baud);
  
}


// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                     
{
  delayTime = analogRead(knobPin);
  buttonState = digitalRead(buttonPin);
  
  if (buttonState == 1)
  {
    
    // if button was just pressed, get new random function
    if (trigger == 0)
    {
      // ensure different trigger each press
      while (trigger == lastTrigger)
      {
        trigger = random(1, 6);
      }
      
      lastTrigger = trigger;
    }
    
    switch (trigger)
    {
       
      case 1:
        Serial.println("Trigger 1: downStep");
        downStep();
        break;
         
      case 2:
        Serial.println("Trigger 2: downUp");
        downUp();
        break;
         
      case 3:
        Serial.println("Trigger 3: upStep");
        upStep();
        break;
       
      case 4:
        Serial.println("Trigger 4: allBlink");
        allBlink();
        break;
       
      case 5:
        Serial.println("Trigger 5: scroll");
        scroll();
        break;
         
      case 6:
        Serial.println("Trigger 6: bounce");
        bounce();
        break;
       
      default:
        trigger = 0;
        break;
       
    }
    
    displayed = 1;
     
  }
  else
  {
    // but was released, turn off LEDs and reset trigger and pin
    setLEDs(LOW, LOW, LOW);
    trigger = 0;
    at = 1;
    displayed = 0;
  }

}
